package com.gongjian.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gongjian.database.entity.User;
import com.gongjian.database.service.WxUserService;
import com.gongjian.utile.CodeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
/**
 * @author 董浩
 * @Description
 * @create 2019-03-20 20:40
 */
@RestController
public class Common {
    @Autowired
    WxUserService wxUserService;

    @PostMapping("/common/getSessionId")
    public String getSessionId(HttpSession session){
        CodeEntity codeEntity=new CodeEntity(200);
        JSONObject data=new JSONObject();
        data.put("sessionId",session.getId());
        codeEntity.setData(data);
        return  codeEntity.toJSONString();
    }
    @PostMapping("/common/isLogin")
    public String isLogin(HttpSession session){
        if(session.getAttribute("user")!=null){
            User user=((User)session.getAttribute("user"));
            if(user.getUserPower()==0){
                CodeEntity codeEntity=new CodeEntity(202,"没有权限");
                return  codeEntity.toJSONString();
            }
            CodeEntity codeEntity=new CodeEntity(200,"已登录");
            System.out.println("isLogin:"+ session.getId());
            return  codeEntity.toJSONString();
        }
        else {
            CodeEntity codeEntity=new CodeEntity(201,"未登录");
            return  codeEntity.toJSONString();
        }
    }
}
